package com.itic.mobile.jtt;



import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itic.appbase.framework.utils.HttpRequestUtils;
import com.itic.mobile.base.BaseMobileInterface;

import net.sf.json.JSONObject;


/**
 * 京东联盟
 * @author Administrator
 *
 */
@Controller
@RequestMapping(value = "/mobile/jtt")
public class JttInterface extends BaseMobileInterface {
	
	//商品列表
	private static String goodsList = "http://japi.jingtuitui.com/api/get_goods_list";// appid=你的appid&appkey=你的appkey&page=1&num=30&type=10&rank=sift
	//商品详情
	private static String goodsDetail = "http://japi.jingtuitui.com/api/get_goods_info";// appid=你的appid&appkey=你的appkey&gid=11220136891
	//优惠券信息
	private static String goodsCoupon = "http://japi.jingtuitui.com/api/get_coupom_info";// appid=你的appid&appkey=你的appkey&gid=11220136891
	//二合一转链接
	private static String convertUrl = "http://japi.jingtuitui.com/api/get_goods_link";// appid=你的appid&appkey=你的appkey&unionid=你的unionid&positionid=你的推广位id&gid=商品id&coupon_url=优惠券链接
	
	private static String appkey = "23D0D64434349441EB49DA44F13EDB69";
	private static String appid = "857472d299d84727a7d021ae40d3bc8b";
	
	
	/**
	 * 初始化京东联盟配置信息
	 * @param unionid
	 * unionid 1000466519
	 * key 758E9DE6C40A4C97C3195D1E383E41BE
	 * secret 50176e262f10453d97ce5fba2918dc3d
	 * access_token 8de91341-9d1d-4216-95bf-4e8bc7f82454
	 * position 1091396120
	 */
	@RequestMapping(value = "/getGoods")
	@ResponseBody
	public Map<String, Object> getUrl( HttpServletRequest request, HttpServletResponse response, String uid, String pid, String sku ) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try{
			
		}catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("JdlmInterface", "getUrl", e.toString(), "京东联盟普通二合一转链接", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		return resultMap;
	}
	
	
	
	/**
	 * 初始化京东联盟配置信息
	 * @param unionid
	 * unionid 1000466519
	 * key 758E9DE6C40A4C97C3195D1E383E41BE
	 * secret 50176e262f10453d97ce5fba2918dc3d
	 * access_token 8de91341-9d1d-4216-95bf-4e8bc7f82454
	 * position 1091396120
	 */
	@RequestMapping(value = "/getGoodsInfo")
	@ResponseBody
	public Map<String, Object> getGoodsInfo( String uid, String pid, String sku, String conUrl ) throws Exception{
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try{
			
		}catch (Exception e) {
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("JdlmInterface", "getConUrl", e.toString(), "京东联盟优惠券二合一转链接", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		return resultMap;
	}
	
	
	
	
	
	/**
	 * 
	 * public JdClient client=new DefaultJdClient(SERVER_URL,accessToken,appKey,appSecret);
	 * https://oauth.jd.com/oauth/authorize?response_type=code&client_id=YOUR_CLIENT_ID&
		redirect_uri=YOUR_REGISTERED_REDIRECT_URI&state=YOUR_CUSTOM_CODE
	 */
	@RequestMapping(value = "/getCoupomInfo")
	@ResponseBody
	public JSONObject getCoupomInfo( String key){
		String url = "https://oauth.jd.com/oauth/authorize?response_type=code&client_id="+key+"&redirect_uri=http://www.jhjvip.cn&state=code";
		return HttpRequestUtils.httpGet(url);
	}
	
	/**
	 * https://oauth.jd.com/oauth/token?grant_type=authorization_code&client_id=758E9DE6C40A4C97C3195D1E383E41BE&
redirect_uri=http://www.jhjvip.cn&code=2o5nGz&state=code&client_secret=50176e262f10453d97ce5fba2918dc3d
       
	 */
	@RequestMapping(value = "/getGoodsLink")
	@ResponseBody
	public String getGoodsLink( String code, String key, String secret ){
		String result = "";
		try{
			
	    } catch (Exception e) {
	        e.printStackTrace();
	    }
		return result;
	}
}